﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Eatime.Common;
using Eatime.DataServiceProxy;
using Eatime.Entitys;
using Windows.Storage;

namespace Eatime.Bussiness
{
    public class ShopService
    {
        public static Shops GetLocalShop(ShopParams pShopParams)
        {
            return new DataServicesProxy().GetDatas<Shops, ShopParams>(pShopParams, HttpMethod.Get, "Shop/ShopsForMobile");
        }
        public static List<Menu> GetShopMenu(MenuParams menuParams)
        {
            return new DataServicesProxy().GetDatas<List<Menu>, MenuParams>(menuParams, HttpMethod.Get, "Shop/ShopSellerCats");
        }
        public async static void AddFavoriteShop(Shop shop)
        {
            List<Shop> shops = null;
            //var results = SettingHelper.ReadSetting<List<Shop>>("FavoriteShops", typeof(List<Shop>));
            //if (results.Result.Success)
            //{
            //    shops = (List<Shop>)results.Result.Result;
            //}
            if (shops==null)
            {
                shops = new List<Shop>();
            }
            shops.Add(shop);
            SettingHelper.SaveSetting("FavoriteShops", shops);
        }
        public  static List<Shop> GetFavoriteShop()
        {
            List<Shop> shops = null;
            //var results = SettingHelper.ReadSetting<List<Shop>>("FavoriteShops.txt", typeof(List<Shop>));
            //if (results.Result.Success)
            //{
            //    shops = (List<Shop>)results.Result.Result;
            //}
             
            if (shops==null)
            {
                shops = new List<Shop>();
            }
            return shops;
        }
        public static Shops GetRecommendShop(RecommendParams recommendParams)
        {
            return new DataServicesProxy().GetDatas<Shops, RecommendParams>(recommendParams, HttpMethod.Get, "Shop/ShopsForMobile");
        }
        public static ShopReviewData GetShopView(ShopViewParam shopViewParam)
        {

            return new DataServicesProxy().GetDatas<ShopReviewData, ShopViewParam>(shopViewParam, HttpMethod.Get, "Shop/GetShopReviews");
        }
        public static void AddHistoryShop(Shop shop)
        {
            List<Shop> shops = null;
            //var results = SettingHelper.ReadSetting<List<Shop>>("HistoryShops.txt", typeof(List<Shop>));
            //if (results.Result.Success)
            //{

            //    shops = (List<Shop>)results.Result.Result;
            //}
            if (shops == null)
            {
                shops = new List<Shop>();
            }
            if (shops.Count>20)
            {
                shops.RemoveAt(20);
            }
            shops.Add(shop);
            SettingHelper.SaveSetting("HistoryShops.txt", shops);
        }
        public static List<Shop> GetHistoryShop()
        {
            List<Shop> shops = null;
            //var results = SettingHelper.ReadSetting<List<Shop>>("HistoryShops.txt", typeof(List<Shop>));
            //if (results.Result.Success)
            //{

            //    shops = (List<Shop>)results.Result.Result;
            //}
            if (shops == null)
            {
                shops = new List<Shop>();
            }
            return shops;
        }

    }
}
